package com.qy139.order.service.impl;

import com.qy139.entity.RoomOrder;
import com.qy139.order.mapper.RoomOrderMapper;
import com.qy139.order.service.IRoomOrderService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qy139.util.Result;
import com.sun.org.apache.bcel.internal.generic.NEW;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author hyh
 * @since 2021-12-01
 */
@Service
public class RoomOrderServiceImpl extends ServiceImpl<RoomOrderMapper, RoomOrder> implements IRoomOrderService {
    @Resource
    private RoomOrderMapper mapper;


    @Override
    public List<Map> getAllSeat(Integer id,Integer storeId) {
        List<Map> maps = mapper.selectOrder(id,storeId);
        List<Integer> list = new ArrayList<>();
        if (maps!=null && maps.size() > 0){
            for (Map mp : maps) {
                Integer seatId = (Integer) mp.get("seatId");
                mapper.updateStatus(seatId,id);
                list.add(seatId);
        }
          mapper.updateStat(list,id);
        }else {
        mapper.updateStatu(id);
        }
        return mapper.getAllSeat(id);
    }

    @Override
    public List<Map> getAllRoom(Integer id) {
        return mapper.getAllRoom(id);
    }

    @Override
    public Map getCard(Integer cardnum) {
        return mapper.getCard(cardnum);
    }

    @Override
    public List<Map> selectTime(RoomOrder roomOrder) {
        List<Map> maps = mapper.selectTime(roomOrder);
        System.out.println(maps+"222222222222222222222222222222222222222222222222222222222222222222");
        List<Integer> list = new ArrayList<>();

        if (maps!=null && maps.size() > 0){
            for (Map mp : maps) {
                Integer seatId = (Integer) mp.get("seat_id");
                Integer storeId = (Integer) mp.get("store_id");
                Integer id = (Integer) mp.get("room_id");
                mapper.updateStatus(seatId,id);
                list.add(seatId);
            }
            Integer id = roomOrder.getRoomId();
            Integer storeId = roomOrder.getStoreId();
            mapper.updateStat(list,id);
        }

        return mapper.getAllSea(roomOrder.getRoomId());
    }

}
